from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from device.router.control import create_router


def create_device_app(control_handler) -> FastAPI:
    _ = FastAPI()
    _.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    router = create_router(control_handler)
    _.include_router(router, prefix="/api")
    return _
